package com.uenpay.im.serializations;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.qyx.android.entity.GroupMemberEntity;

/**
 *
 * @author SL
 * @copyright http://www.qiyunxin.com
 * 
 */
public class GroupMemberSerializer {
	public static GroupMemberEntity deserializeUser(JSONObject json) {
		GroupMemberEntity entity = new GroupMemberEntity();
		if (json == null) {
			return entity;
		}
		entity.nick_name = json.optString("nickname");
		entity.cust_id = Long.valueOf(json.optString("custid"));
		entity.group_member_json = json.toString();
		return entity;
	}

	public static ArrayList<GroupMemberEntity> deserializeUsers(JSONArray json) {
		ArrayList<GroupMemberEntity> entities = new ArrayList<GroupMemberEntity>();
		for (int i = 0; i < json.length(); i++) {
			entities.add(deserializeUser(json.optJSONObject(i)));
		}
		return entities;
	}

	public static ArrayList<Long> deserializeAllChatCustDelete(JSONArray jsons) {

		ArrayList<Long> delete_cust_id = new ArrayList<Long>();
		for (int i = 0; i < jsons.length(); i++) {
			try {
				delete_cust_id.add(jsons.getLong(i));
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
		return delete_cust_id;
	}
}
